import java.util.Scanner;

public class Main {

    //排列问题：

//定义全局变量 ans 用于记录路径，vis 用于标记已使用过的数
//递归 dfs(int pos,int n)
//路径的终止条件：pos > n
//遍历输出
//记录路径条件：if(vis[i] == 0)进入

    public static int[] ans = new int[10];
    public static int[] vis = new int[10];

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        for(int i = 1; i <= n; i++){
            ans[i] = 0;
            vis[i] = 0;
        }
        dfs(1,n);//当前位置

        scan.close();
    }

    private static void dfs(int pos, int n) {
        if(pos > n){
            for (int i = 1; i < n; i++) {
                System.out.print(ans[i] + " ");
            }
            System.out.println();
            return ;
        }

        for (int i = 1; i <= n; i++) {
            if(vis[i] == 0){
                ans[pos] = i;
                vis[i] = 1;
                dfs(pos + 1,n);
                ans[pos] = 0;
                vis[i] = 0;
            }
        }
    }

}
